package org.dna.wicketui;

import java.util.List;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.dna.uimodel.MenuItem;

public class SummaryPanel extends Panel {

    private static final long serialVersionUID = 1L;

    public SummaryPanel(String id) {
        super(id);
        add(new Label("numberActivities", "5"));
        clearContextMenu();
    }

    public void setContextMenu(List<MenuItem> contextmenu) {
        ListView lv = new ListView("contextmenu", contextmenu) {

            @Override
            protected void populateItem(ListItem item) {
                MenuItem menuitem = (MenuItem) item.getModelObject();
                item.add(menuitem.createMenu());
            }
        };
        remove("contextmenu");
        add(lv);
    }

    private void clearContextMenu() {
        WebMarkupContainer parent = new WebMarkupContainer("contextmenu");
        add(parent);
        WebMarkupContainer link = new WebMarkupContainer("link");
        link.add(new WebMarkupContainer("caption"));
        parent.add(link);
        parent.setVisible(false);
    }
}
